package com.scnb.Singleton;

public class Mgr05 {
    private static Mgr05 INSTANCE;

    private Mgr05(){}

    public static Mgr05 getINSTANCE(){
        if (INSTANCE == null){
            //妄图通过减小同步代码块的方式提高效率，但是这样方法是不可行的
            //可以自己模拟两个线程来分析
            synchronized(Mgr05.class){
                try{
                    Thread.sleep(20);
                }catch(InterruptedException e){
                    e.printStackTrace();
                }
                INSTANCE = new Mgr05();
            }
        }
        return INSTANCE;
    }

    public void m(){
        System.out.println("m");
    }

    public static void main(String[] args){
        for (int i = 0; i < 100; i++) {
            new Thread(()->{
                System.out.println(Mgr05.getINSTANCE().hashCode());
            }).start();
        }
    }
}
